package com.his.registration.controller;

import com.his.common.Result;
import com.his.dto.DiseaseCondition;
import com.his.registration.pojo.Disease;
import com.his.registration.service.DiseaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/3 11:55
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/disease")
public class DiseaseController {
    @Autowired
    private DiseaseService diseaseService;

    //查看所有疾病信息
    @RequestMapping("/selectAll")
    public Result selectAll(){
        List<Disease> diseaseList = diseaseService.selectAll();
        return Result.success(diseaseList);
    }

    //模糊搜索疾病信息
    @RequestMapping("/selectByCondition")
    public Result selectByCondition(DiseaseCondition diseaseCondition) {
//        String diseaseName =diseaseCondition.getDiseaseName();
        //避免特殊字符引起的请求错误，你可以进行 URL 编码来对参数值进行处理。URL 编码会将特殊字符转换为特定的编码形式，确保它们被正确传递并得到正确处理。
//        String encodedDiseaseName = URLEncoder.encode(diseaseName, "UTF-8");
//        System.out.println(encodedDiseaseName);
//        diseaseCondition.setDiseaseName(encodedDiseaseName);
        List<Disease> diseaseList = diseaseService.selectByCondition(diseaseCondition);
        return Result.success(diseaseList);
    }
}
